<?php
class MedSocFace300x250 extends WP_Widget {

	/* construtor */
	function __construct() {
		parent::__construct('media-face-300x250', 'Aves PT Bloco FB', array( 'description' => 'Bloco do Face Book 300x400.' ));
	}

	/* display widget */
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );
		$title = empty ( $instance['title']) ? 'Publicidade' : apply_filters('widget_title', $instance['title'] );
		$comprimento = empty ($instance['comprimento']) ? '300' : apply_filters('widget_title', $instance['comprimento']);
		$altura = empty ($instance['altura']) ? '400' : apply_filters('widget_title', $instance['altura']);		
		do_vertical_space( '10' );
		?>
		<!-- Código referente ao Facebook -->
		<div id="fb-root"></div>
		<script>(function(d, s, id) {
			var js, fjs = d.getElementsByTagName(s)[0];
			if (d.getElementById(id)) return;
			js = d.createElement(s); js.id = id;
			js.src = "//connect.facebook.net/pt_PT/all.js#xfbml=1";
			fjs.parentNode.insertBefore(js, fjs);
		}(document, 'script', 'facebook-jssdk'));</script>
		<?php $ref = 'fb-'.$comprimento.'x'.$altura; ?>		
		<div id="fb-300x400">
			<span class="pub-retranca">FACEBOOK</span>
			<div class="fb-300x400">
				<div class="fb-like-box" data-href="https://www.facebook.com/Avespt" data-width="<?php echo $comprimento;?>" data-height="<?php echo $altura;?>" data-show-faces="true" data-stream="false" data-header="false"></div>
			</div>
		</div>
	<?php
	}
	
	/* update/save function */
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['comprimento'] = strip_tags($new_instance['comprimento']);
		$instance['altura'] = strip_tags($new_instance['altura']);
		return $instance;
	}
	
	/* admin control form */	
	function form( $instance ) {
		$instance = wp_parse_args((array) $instance, array( 'title' => '', 'comprimento' => '', 'altura' => '' ) );
		$title = strip_tags( $instance['title'] ); 
		$comprimento = strip_tags( $instance['comprimento'] );
		$altura = strip_tags( $instance['altura'] );?>
		<p>
		  <label for="<?php echo $this->get_field_id('title');?>"><?php _e('Título: ') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($title); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('comprimento');?>"><?php _e('Comprimento: ') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('comprimento'); ?>" name="<?php echo $this->get_field_name('comprimento'); ?>" value="<?php echo esc_attr($comprimento); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('altura');?>"><?php _e('Altura: ') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('altura'); ?>" name="<?php echo $this->get_field_name('altura'); ?>" value="<?php echo esc_attr($altura); ?>">
		</p>
	<?php	
	}
}
?>